home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 7.1 KB | 286 lines | [TEXT/MPS ] |
- {$S Task}
- UNIT Task;
- {© G. Sawitzki, StatLab Heidelberg 1986-1991}
-
- INTERFACE
-
- USES
- MacUnits,
- StdTools,Generic,NetWork,NetWorkLookUp,ObjIntf,SchedulerUnit,NetsimGlobal,
- UToy,
- HistogramUnit,HistogramIO;
-
-
-
- CONST
- MyFileType = 'TEXT'; {Your default file type for files you create}
- cDefaultDistribution='GAUS';
- cDefaultDisplay='SCAT';
- mDistribution=4; {additional menus}
- mDisplay=5;
- mControl=128;
-
- VAR
- {channel file identification through the standard tools package}
- OutSFReply, InSFReply : TFileInfo; {use these variables, for example}
- OutFile, InFile : Text;
-
-
- gNextNetRefresh:longint;
-
- {----------------- Main Routines ------------------}
-
- {You will have to change these routines to adapt to your needs.
- Arrange your program in a reentrant way.
- You can define (global) state variables in this unit.}
-
-
- PROCEDURE MyInit (FileType : OSType);
- {Will be called once when the application starts. Initialize
- your global variables in MyInit. FileType generically is set
- to the constant MyFileType.
- In MacApp the corresponding method is TEvtHandler.IApplication.}
-
- PROCEDURE MyTask (phase : BackPhase);
- {Application equivalent of system Task: this is the core of
- your main program. It will be called periodically unless
- more important events are pending. phase will show you whether
- something happened in the meantime -- see the TYPE BackPhase
- defined in StdTools.
- In MacApp the corresponding method is TEvtHandler.DoIdle.}
-
- PROCEDURE MyCleanUp;
- {will be called once when the application is about to finish.
- Save your results here, clean up any gaarbage you have made.}
-
-
- {-------------------- routines on request -------------------------}
- {These routines are called when you are asked to acces a document, eg.
- by a menu selection. The CmdNumbers are constants defined in StdTools}
-
-
- PROCEDURE doopen (itsCmdNumber : cmdnumber);
-
- PROCEDURE dosave (itsCmdNumber : cmdnumber);
-
- PROCEDURE doclose (itsCmdNumber : cmdnumber);
-
-
- IMPLEMENTATION
- var gProtocolOn:boolean;
- gnrResults:longint; {last shown to user}
- nrResults:longint; {delta since last shown to user}
-
- procedure DebugStrNum(s:str255;n:longint);
- var s1:str255;
- begin
- NumToString(n,s1);
- debugstr(concat(s,' ',s1));
- end;
-
- type tConfigurationHandle=^tConfigurationPtr;
- tConfigurationPtr=^tConfiguration;
- tConfiguration=record
- version:longint;
-
- Protocolversion:integer;{not used}
- {MPW Pascal has boolean bytes; Resedit words= byte+pad!}
- MasterProtocolOn:boolean;
- pad2:boolean;
- SlaveProtocolOn:boolean;
- pad21:boolean;
-
- ShowControlMenu:boolean;
- pad22:boolean;
-
-
- GenerateSamples:boolean; {not used. should switch to a totally controlled situation}
- pad3:boolean;
- UseDelays:boolean; {add a delay to task. }
- pad4:boolean;
-
- RandomDelays:boolean; {use a random delay. uses exponential distribution}
- pad5:boolean;
- UseFailureRates:boolean; {use a random delay. uses exponential distribution}
- pad6:boolean;
- UseMessageSizes:boolean; {use a random delay. uses exponential distribution}
- pad7:boolean;
-
- TaskCoreTime:integer; {used for master as well}
- TaskDefinitionTime:integer; {used for master as well}
- TaskUpdateTime:integer; {used for master as well}
- ReplyFailureRate:integer; {used for master as well}
- AcceptFailureRate:integer; {used for master as well}
- SampleSize:integer;
-
- MinPrioSize:integer; {not used}
- MinCoreSize:integer; {not used}
-
- UseBroadCast:boolean; {use -1 broacast address}
- pad8:boolean;
-
- MaxNrNodes: integer;
- ComputationGrainSize: integer;
- TickleInterval: integer;
- WaitInterval: integer;
- end;
- var theConfiguration:tConfiguration;
-
- {*************************************************}
-
-
- var gMsgHeader:tMsgHeader; {holds distribution token, displaytoken, samplesize, version}
-
- function LongintStr(l:longint):str15;
- var trick:packed record
- case boolean of
- true:(s:signedbyte;sl:longint);
- false:(s15:str15);
- end;
- begin
- trick.s:=4;
- trick.sl:=l;
- longintstr:=trick.s15;
- end;
-
- function MsgHeaderStr(var hdr:tMsgHeader):str255;
-
- begin
- with hdr do MsgHeaderStr:=concat(Longintstr(ContentsToken),' ',
- Longintstr(DistributionToken),' ',
- Longintstr(DisplayToken));
- end;
-
- procedure prepareMessageHeader(var aMsgHeader:tMsgHeader;myAction:tAction);
- begin
- {set correct info to header}
- with aMsgHeader do begin
- sampleSize:=TheConfiguration.SampleSize;
- version:=cMyMsgHeaderVersion;
- traceInfo:=gnrResults+nrResults;
- action:=myAction;
-
- DistributionToken:=longint(cDefaultDistribution);
-
- DisplayToken:=longint(cDefaultDisplay);
- end;
- end;
-
- {*************************************************}
- var localhist,totalhist:histtype;
- localstat,totalstat:tStatType;
- localhrect,totalhrect:rect;
- localsrect,totalsrect:rect;
- pcomprect,qcomprect:rect;
- nform:decform;
-
- var StatisticWindow:WindowPtr;
- StatisticWindowRec:WindowRecord;
- {implementation for handlers}
-
- procedure initStatistics;
- var safeport:grafptr;myPic:PicHandle;
- begin
- initHistogram(localhist,'local');
- initHistogram(totalhist,'total');
- initstat(localstat,'local');
- initstat(totalstat,'total');
- if statisticwindow<>nil then begin
- getport(safeport);
- setport(statisticwindow);
- mypic:=getwindowPic(statisticwindow);
- if mypic<>nil then killpicture(myPic);
- setwindowpic(statisticwindow,nil);
- eraserect(thePort^.portrect);
- setport(safeport);
- end;
- end;
-
- procedure DrawStatisticWindow;
- var safeport:grafptr;myPic:PicHandle;
- begin
- if statisticwindow<>nil then begin
- getport(safeport);
- setport(statisticwindow);
- mypic:=getwindowPic(statisticwindow);
- if mypic<>nil then killpicture(myPic);
- mypic:=OpenPicture(thePort^.portrect);
- showhistogram(localhist,localhrect,nform);
- showhistogram(totalhist,totalhrect,nform);
- reportstat(localstat,localsrect,nform);
- reportstat(totalstat,totalsrect,nform);
- closepicture;
- setwindowpic(statisticwindow,mypic);
- eraserect(thePort^.portrect);
- drawpicture(mypic,thePort^.portrect);
- validrect(thePort^.portrect);
- setport(safeport);
- end;
- end;
-
- var BaseWindow:WindowPtr;
- baserect:rect;
- RecordWindow:WindowPtr;
- minRect,maxRect:rect;
- minPic,maxPic:PicHandle;
- minrecord,maxrecord:extended;
- { discard garbage below }
- var
- gSoldResults:str255;
- gsoldResults2:Str255;
- goldTime:longint;
-
- sLastTicks:longint;
- sMeanTicks:real;
-
- const
- TicksDelta=300;
- cNetRefreshDelta=60;
- var nextTicks:longint;
- oldTime:longint;
- sResults,sTicks:str255;
-
- { $I statistics.impl.p}
-
- procedure sInit;
- begin
- sLastTicks:=tickCount;
- sMeanTicks:=100; {a random number to start off- we are using provisional means}
- end;
-
- procedure NoteStatistics(x:extended;islocal:boolean);
- begin
- if IsLocal then begin
- AddStat(x,localstat);addhist(x,localhist);
- end;
-
- AddStat(x,totalstat);addhist(x,totalhist);
- end;
-
- procedure NewRecordPicture;
- var myPic:PicHandle;var savePort:GrafPtr;
- begin
- GetPort(SavePort);
- SetPort(RecordWindow);
- myPIc:=GetWindowPic(RecordWindow);
- if myPic<>nil then killPicture(myPic);
- myPic:=openPicture(RecordWindow^.portrect);
- showpen;
- EraseRect(RecordWindow^.portrect);
- {framerect(minrect);fillrect(minrect,ltGray);}
- DrawPicture(minPic,MinRect);
- DrawPicture(maxPic,MaxRect);
-
- hidepen;
- closePicture;
- setwindowpic(RecordWindow,myPic);
- SetPort(SavePort);
- end;
-
- {$I taskCore.impl.p}
- {$I task.handlers.impl.p}
- {$I task.master.impl.p}
- {$I task.reply.impl.p}
- {$I task.slave.impl.p}
- {$I task.impl.p}
- END.